$(function() {
    var contextPath = function() {
        return  "/" + location.pathname.split("/")[1];
    }

    function getValue(name){
        var str=window.location.search;
        if (str.indexOf(name)!=-1){
            var pos_start=str.indexOf(name)+name.length+1;
            var pos_end=str.indexOf("&",pos_start);
            if (pos_end==-1){
                return str.substring(pos_start);
            } else {
                return str.substring(pos_start,pos_end);
            }
        } else {
            return "";
        }
    }


	var collegeid = 11;//collegeid=11 即为运营培训系统
	
	getHeadline();
	getCollegeContext();
	
	function getCollegeContext(e) {
		$.ajax({
			url : contextPath()+"/airuc/getcollegebyid?collegeid="+collegeid,
			type : "get",
			dataType : "json",
			success : function(data) {
				if (data.success) {
					createPage(data.college);
				}
			}
		});
	}
	
	function createPage(data) {
		var html = '';
		data.courseList.map(function(item, index) {
			html += "<div class='weui-panel__hd'><h1 style='color:0066CC; text-align:center'>"+item.courseName+"</h1></div>"
					+ "<div class='weui-panel__bd'>";
			item.lessonList.map(function(item1, index1) {
				if (index1<2) {
					//只显示两个课程
					html += "<a href='yylesson.html?lessonid="+item1.lessonID+"' class='weui-media-box weui-media-box_appmsg'>"
		    		+ "<div class='weui-media-box__hd'>"
		    		+ "<img class='weui-media-box__thumb' src='"+item1.lessonImg+"'>"
		    		+ "</div>"
		    		+ "<div class='weui-media-box__bd'>"
		    		+ "<h4 class='weui-media-box__title'>"+item1.lessonName+"</h4>"
		    		+ "<p class='weui-media-box__desc'>"+item1.lessonDesc+"</p>"
		    		+ "</div>"
		    		+ "</a>";
				}
			});
			html += "</div>";
			html += "<div class='weui-panel__ft'>"
					+ "<a href='yycourse.html?courseid="+item.courseID+"' class='weui-cell weui-cell_access weui-cell_link'>"
					+ "<div class='weui-cell__bd'>查看更多</div>"
					+ "<span class='weui-cell__ft'></span>"
					+ "</a>"
					+ "</div>";
		});
		$('#id-classlist').html(html);   
	}
	
	function getHeadline(e) {
		$.ajax({
			url : contextPath()+"/airuc/getheadlinebycollegeid?collegeid="+collegeid,
			type : "get",
			dataType : "json",
			success : function(data) {
				if (data.success) {
					createHeadline(data.HeadlineList);
				}
			}
		});
	}
	
	function createHeadline(data) {
		var html = '';
		data.map(function(item, index) {
			html += "<div class='swiper-slide'>" +
						"<a href='"+item.lineLink+"'>" +
						"<img src='"+item.lineImg+"' width='100%'  height='200' alt=''>" +
						"</a>" +
					"</div>";
		});
		$('#id-headline').html(html);    
		$(".swiper-container").swiper({
	        loop: true,
	        autoplay: 3000
	    });    
	}

    FastClick.attach(document.body);
});